<?php
if (eregi("common.php",$_SERVER['SCRIPT_NAME'])) {
    Header("Location: ../index.php");
    die();
}

class Common {

    // parameters
    var $page;
	var $noTagsError  = false; // whether an error should be printed
	                           // if no tags are designated


	// {{{ logo()
    //
    // Print the navigation menu for visitors.
    //
    // IN: -
    // OUT: string [html text of the logo]
    //
    function logo()
	{
	    global $html,$tpl;
		
		$images = "";
		for($i=1;$i<=4;$i++)
		{
		    $images.= "<tr>";
		    for($j=1;$j<=9;$j++)
			{
			    $image = ($i-1)*9+$j;
				if ($image == 9) { $newlang = "de"; }
				elseif ($image == 15) { $newlang = "en"; }
				elseif ($image == 26) { $newlang = "ru"; }
				
				if ($image == 9 || $image == 15 || $image == 26)
				{
				    $images.= $html->td(
			    	    "<a href='index.php?newlang=$newlang'>".
		    			"<img src='".$tpl->tplDirectory."images/$image.gif' width='39' height='40' border='0'>".
					    "</a>"
				    );
                }
				else
				{
				    $images.= $html->td("<img src='".$tpl->tplDirectory."images/$image.gif' width='39' height='40' border='0'>");
				}
			}
		    $images.= "</tr>";
		}
		
		$str =
		$html->table(
		    $images
		,"322",0,0,1,"","");
		
		return $str;
	}


    function selectLang()
	{
        global $lang,$html;
		
		$langstr = "<table border='0' cellpadding='4' cellspacing='0'><tr>";
		$langstr.= "<td><small>select language:</small></td>";
		foreach ($lang->available as $x)
	    {
		    $langstr.= "<td";
			if ($x == $lang->current) { $langstr.= " bgcolor='#badeef'"; }
	        $langstr.= "><a href='index.php?";
	        $langstr.= "newlang=".$x."'><img src='language/".$x.".gif' width='14' height='11' border='0'></a>";
			$langstr.= "</td>";
	    }
		$langstr.= "</tr></table>";
	    
		$str.= $html->table(
		    $html->tr(
		        $html->td(
	                $langstr
                ,2)
			,"1")
		,"100%","","2");
	    return $str;
    }


	// Navigationsleiste direkt unter dem Logo
    function navMenuTop() {
	    global $table,$db,$html,$lang,$page;
		
		$str.= "<nobr>";
		$result = $db->query("SELECT * FROM $table->dir WHERE language='$lang->current' AND parent='0' ORDER BY id");
		$i = 1;
		    while ($row = $db->nextRecord($result))
    		{
			    if ($row->id == $page->dir)
				{
				    $str.=" <span style='background-color:#badeef'>&nbsp;".$row->name.".</span>";
				}
				else
				{
					// Fuer den Folder 'Novosti' im russischen Bereich der Seite wird die Seite mit der groessten ID angezeigt
				    $str.= " &nbsp;<a style='text-decoration:none' href='index.php?id=".$this->getSmallestId($lang->current, $row->id, $row->id==4)."'>".$row->name.".</a>";
				}
		    }
		
		return $str;
	}


    function getSmallestId ($language, $dir = 0, $returnBiggestId = false) {
	    global $table,$db;
		
		$query = "SELECT * FROM $table->page WHERE language='$language'";
		if ($dir>0) { $query.= " AND dir='$dir'"; }
		$query.= " ORDER BY id ".($returnBiggestId ? 'DESC ' : '')."LIMIT 0,1";
		$result = $db->query($query);
		if ($db->numRows($result) == 0)
		{
		    $id = 0;
		}
		else
		{
		    $row = $db->nextRecord($result);
			$id  = $row->id;
		}
		
		return $id;
	}


    function Bottom($id) {
	$str = "
	<table border=0 width='100%' cellpadding=3 cellspacing=0>
	<tr>
	    <td class='navmenu'>
			<a href='print.php?id=$id' target='_blank'>Print version</a> | <a href='admin.php'>Administration</a> 
		</td>
		<td align='right' class='navmenu'>
		    <small>&copy; dankezu.de, Berlin 2006-".date('Y', time())."</small>
		</td>
	</tr>
	</table>";
	
	return $str;
	}
	
	
		function getRoute($id = 0) {
	    global $table,$db,$admin,$page;
	    
	    $str = "";
	    $result = $db->query("SELECT * FROM $table->dir WHERE id='$id' AND language='$page->language'");
	    if ($db->numRows($result) > 0)
        {
	    	$row = $db->nextRecord($result);
			if ($row->parent==0) { $str.="<b>"._YOUAREHERE.": </b>"; }
	    	$str.= $this->getRoute($row->parent)."<a href='".GLOBAL_SELF."?op=d&id=".$this->getSmallestId($page->language,$id)."'><b>".$row->name."</b></a> / ";
	    }
	    
	    return $str;
	}
}
?>